﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter13.Code03.Code02.Example01
{
    using Timer = System.Timers.Timer;
    using System.Timers;
    using System.Threading;

    public class Demo
    {
        private static int counter = 0;
        private static string displayString = "This string will appear one letter at a tiem. ";

        public static void Begin()
        {
            Timer myTimer = new Timer(100);
            myTimer.Elapsed += new ElapsedEventHandler(WriteChar);
            myTimer.Start();
            Thread.Sleep(200);
            Console.ReadLine();
            myTimer.Stop();
        }

        private static void WriteChar(object sender, ElapsedEventArgs e)
        {
            Console.Write(displayString[counter++ % displayString.Length]);
        }
    }
}
